package demoMod.stsconsole.events.exordium;

import demoMod.stsconsole.ConsoleEntry;
import demoMod.stsconsole.cards.curses.Parasite;
import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.events.AbstractEvent;
import demoMod.stsconsole.events.EventNode;
import demoMod.stsconsole.events.EventOption;
import demoMod.stsconsole.helpers.PromptHelper;
import demoMod.stsconsole.interfaces.DropRewardSubscriber;
import demoMod.stsconsole.relics.OddMushroom;
import demoMod.stsconsole.rewards.CardReward;
import demoMod.stsconsole.rewards.PotionReward;
import demoMod.stsconsole.rewards.RelicReward;
import demoMod.stsconsole.rooms.AbstractRoom;
import demoMod.stsconsole.rooms.EventRoom;

public class Mushrooms extends AbstractEvent {
    public static final String ID = "Mushrooms";

    public Mushrooms() {
        super(ID);
    }

    @Override
    protected EventNode initOptions() {
        EventNode rootNode = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                if (!isActive) {
                    next.get(selectedIndex).onChooseOption(optionIndex);
                    return;
                }
                options.get(optionIndex).onChooseThisOption();
                isActive = false;
            }
        };
        rootNode.bodyText = eventStrings.get(0) + "\n\n" + eventStrings.get(1);
        rootNode.options.add(new EventOption(rootNode) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(2);
            }

            @Override
            public void onChooseThisOption() {
                node.setSelectedIndex(0);
            }
        });
        rootNode.options.add(new EventOption(rootNode) {
            @Override
            public String getUpdatedDescription() {
                return String.format(eventStrings.get(3), (int) (AbstractDungeon.player.getMaxHealth() * 0.25F));
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.player.heal((int) (AbstractDungeon.player.getMaxHealth() * 0.25F));
                AbstractDungeon.player.addCardToMasterDeck(new Parasite());
                node.setSelectedIndex(1);
            }
        });

        EventNode fight = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                updateBodyTextAfterChooseOption = false;
                options.get(optionIndex).onChooseThisOption();
            }
        };
        fight.bodyText = eventStrings.get(4);
        fight.options.add(new EventOption(fight) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(6);
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.currDungeon.currMapNode.room.phase = AbstractRoom.RoomPhase.COMBAT;
                AbstractDungeon.currDungeon.currMapNode.room.enterCombat("3 Mushrooms");
            }
        });

        EventNode eat = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                updateBodyTextAfterChooseOption = false;
                options.get(optionIndex).onChooseThisOption();
            }
        };
        eat.bodyText = eventStrings.get(5);
        eat.options.add(new EventOption(eat) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(7);
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.currDungeon.currMapNode.room.phase = AbstractRoom.RoomPhase.COMPLETED;
                PromptHelper.backwardPrompt();
            }
        });

        rootNode.next.add(fight);
        rootNode.next.add(eat);

        return rootNode;
    }

    @Override
    public void dropReward(EventRoom eventRoom, boolean shouldDropReward) {
        if (shouldDropReward) {
            eventRoom.rewards.add(new CardReward());
            eventRoom.rewards.add(new RelicReward(new OddMushroom()));
            if (AbstractDungeon.potionRng.nextBoolean(0.2F)) {
                eventRoom.rewards.add(new PotionReward());
            }
        }
        ConsoleEntry.triggerSubscribers(DropRewardSubscriber.class, "onDropReward",
                new Class[]{boolean.class}, new Object[]{shouldDropReward});
    }
}
